<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>07.Controls(OrbitControls)</title>
    <style>
        body {
            margin: 0;
        }
    </style>
</head>

<body>

    <script type="module">
        import * as THREE from '/build/three.module.js';
        import { OrbitControls } from '/jsm/controls/OrbitControls.js';
        //生成场景
        const scene = new THREE.Scene();
        //设置相机
        const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
        camera.position.z = 5;
        //设置渲染器
        const renderer = new THREE.WebGLRenderer();
        renderer.setSize(window.innerWidth, window.innerHeight);
        document.body.appendChild(renderer.domElement);
        //生成模型
        const geometry = new THREE.BoxGeometry();
        const material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
        const cube = new THREE.Mesh(geometry, material);
        //设置场景
        scene.add(cube);
        const controls = new OrbitControls( camera, renderer.domElement );
        controls.update();
        //键盘控制相机移动
        function animate() {
            renderer.render(scene, camera);
            requestAnimationFrame(animate);
            controls.update();
        }
        //开始动画
        animate()
    </script>
</body>

</html>